﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using lingopen.Jabil.Server.Models;

namespace lingopen.Jabil.Server.Controllers
{
    public class HomeController : WebController
    {
        public IActionResult Index()
        {

            if (CurrentSession == null)
            {
                return Redirect("/start/index.html#/user/login/redirect=%2F");
            }

            return Redirect("/start/index.html");

            //return Redirect("/apidoc.html");
            //return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        public IActionResult SendEmail(string name, string phone, string email, string message)
        {

            string body = "时间：" + DateTime.Now + "<br/>称呼：" + name + "<br/>邮箱：" + email + "<br/>电话：" + phone + "<br/>咨询内容：" + message;

            try
            {
                lingopen.EmailHelper postEmail = new lingopen.EmailHelper("UOU主页客户加盟邮件", body);
                var res = postEmail.SendEmail();
                if (res)
                    return Json(new { code = 0, msg = "发送成功,感谢您的支持." });
                else
                    return Json(new { code = -1, msg = "发送失败,请重试!" });
            }
            catch (Exception ex)
            {
                return Json(new { code = -1, msg = ex.Message });
            }


        }
    }
}
